From 58d9c3d5bdab3600809f3bc8dd51e328e9755d08 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 18 Jan 2019 14:43:42 +0000 Subject: [PATCH] switch: Update state labels when needed If the text style changes, or the display settings do, we need to update the state labels to ensure that the glyphs are available in the font we're using. --- gtk/gtkswitch.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/gtk/gtkswitch.c b/gtk/gtkswitch.c index cb361c1292..8ade76acdb 100644 --- a/gtk/gtkswitch.c +++ b/gtk/gtkswitch.c @@ -65,6 +65,7 @@ #include "gtkprivate.h" #include "gtkprogresstrackerprivate.h" #include "gtksettingsprivate.h" +#include "gtkstylecontextprivate.h" #include "gtkwidgetprivate.h" #include "a11y/gtkswitchaccessible.h" @@ -399,6 +400,31 @@ gtk_switch_size_allocate (GtkWidget *widget, gtk_widget_size_allocate (priv->off_label, &child_alloc, -1); } +static void +gtk_switch_style_updated (GtkWidget *widget) +{ + GtkSwitch *self = GTK_SWITCH (widget); + GtkCssStyleChange *change; + GtkStyleContext *context; + + GTK_WIDGET_CLASS (gtk_switch_parent_class)->style_updated (widget); + + context = gtk_widget_get_style_context (widget); + change = gtk_style_context_get_change (context); + + if (change == NULL || gtk_css_style_change_affects (change, GTK_CSS_AFFECTS_TEXT)) + gtk_switch_update_state_labels (self); +} + +static void +gtk_switch_display_changed (GtkWidget *widget, + GdkDisplay *previous_display) +{ + GtkSwitch *self = GTK_SWITCH (widget); + + gtk_switch_update_state_labels (self); +} + static void gtk_switch_set_action_name (GtkActionable *actionable, const gchar *action_name) @@ -591,6 +617,8 @@ gtk_switch_class_init (GtkSwitchClass *klass) widget_class->measure = gtk_switch_measure; widget_class->size_allocate = gtk_switch_size_allocate; + widget_class->style_updated = gtk_switch_style_updated; + widget_class->display_changed = gtk_switch_display_changed; klass->activate = gtk_switch_activate; klass->state_set = state_set; -- 2.30.2